<script>
export default {
  name: "index",
  data() {
    return {
      tableData: [
        {
          date: '2016-05-02',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1518 弄'
        },
        {
          date: '2016-05-04',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1517 弄'
        },
        {
          date: '2016-05-01',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1519 弄'
        },
        {
          date: '2016-05-03',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1516 弄'
        }
      ]
    }
  },
  // 定义事件回调函数
  methods: {
    // 编辑数据回调函数
    handleEdit(index, row) {
      console.log(index, JSON.stringify(row));
    },
    // 删除数据回调函数
    handleDelete(index, row) {
      console.log(index, JSON.stringify(row));
    },
    // 复选框回调函数
    handleSelectionChange(val) {
      console.log(JSON.stringify(val))
    },
    // 监听每页显示数据条数的改变
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
    },
    // 监听页码的改变
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
    }
  }
}
</script>

<template>
  <div id="container">
    <div id="btn-header">
      <el-button type="primary" plain size="small">新增</el-button>
      <el-button type="success" plain size="small">批量删除</el-button>
    </div>
    <!-- selection-change  检测复选框的选中状态       -->
    <el-table
        @selection-change="handleSelectionChange"
        :data="tableData"
        stripe
        style="width: 100%">
      <el-table-column
          type="selection"
          width="55">
      </el-table-column>
      <el-table-column
          prop="date"
          label="日期"
      >
      </el-table-column>
      <el-table-column
          prop="name"
          label="姓名"
      >
      </el-table-column>
      <el-table-column
          prop="address"
          label="地址">
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button
              size="mini"
              @click="handleEdit(scope.$index, scope.row)">编辑
          </el-button>
          <el-button
              size="mini"
              type="danger"
              @click="handleDelete(scope.$index, scope.row)">删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <div id="pagination">
      <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :page-sizes="[5, 10, 15, 20]"
          :page-size="5"
          layout="total, sizes, prev, pager, next, jumper"
          :total="100">
      </el-pagination>
    </div>
  </div>
</template>

<style scoped>
#btn-header {
  text-align: left;
  margin-top: 15px;
  margin-bottom: 15px;
}
#container{
  padding: 20px;
}
#pagination{
  margin-top: 15px;
}
</style>